package com.spj.controller;

import com.spj.entity.ResponseInfo;
import com.spj.entity.User;
import com.spj.service.impl.UserServiceDaoImpl;
import com.spj.shiro_mvc.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :spj
 * @Date:2022/4/14
 * @description:
 */
@RestController
public class LoginController {
    @Autowired
    UserServiceDaoImpl userService;
    @RequestMapping("/login")
    public ResponseInfo loginDemo(String username,String password){
        String token= JwtUtil.sign(username,password);
        User user=userService.login(username);
        return user==null?new ResponseInfo(400,"登录失败","账号密码错误"):new ResponseInfo(200,"登录成功","Token:"+token+"----User:"+user);
    }
    @RequestMapping("/test")
    public ResponseInfo loginDemo(){
        return new ResponseInfo(200,"成功","test");
    }
    @RequestMapping("/wrong")
    public ResponseInfo wrong(){
        return new ResponseInfo(400,"未认证","请先登录");
    }
}
